package com.ujiuye.dao;


import com.ujiuye.bean.StudentBean;
import com.ujiuye.utils.PageUtils;

import java.util.List;

public class StudentDao extends BaseDao<StudentBean> {
    //添加方法
    public int addStudent(StudentBean student){
        String sql="INSERT INTO student(sname,sex,age,degree,pic,mark)VALUES(?,?,?,?,?,?)";
        return jUpdate(sql,student.getSname(),student.getSex(),student.getAge(),student.getDegree(),student.getPic(),student.getMark());
    }
    //查询所有学生列表
    public List<StudentBean>findAllStudentByPage(PageUtils pu){
        String sql = "SELECT * FROM student limit ?,?";
        return  jSelect_Multi(sql, StudentBean.class,pu.getStartIndex(),pu.getPageSize());
    }
    //统计
    public int getTotalCount(){
        String sql ="select count(*) from student";
        String obj=jscale(sql).toString();
        return Integer.parseInt(obj);
    }
    //根据学号查询
    public  StudentBean findStudentBySid(int sid){
        String sql = "SELECT * FROM student where sid = ?";
        return jSelect_One(sql,StudentBean.class,sid);
    }
    //修改信息
    public int updateStudent(StudentBean student){
        String sql  = "update student set sname=?,sex=?,age=?,degree=?,pic=?,mark=? where sid = ?";
        return jUpdate(sql,student.getSname(),student.getSex(),student.getAge(),student.getDegree(),student.getPic(),student.getMark(),student.getSid());
    }
    //删除
    public int deleteStudent(int sid){
        String sql ="DELETE FROM student WHERE sid=?";
        return jUpdate(sql,sid);
    }

    //查询用户
    public StudentBean checkSname(String sanme){
        String sql="SELECT * FROM student where sname = ?";
        return  jSelect_One(sql,StudentBean.class ,sanme);
    }

}
